//
//  OrderParticularsGoodsCell.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/5/8.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "OrderParticularsGoodsCell.h"

#import "OrderRefundView.h"

@interface OrderParticularsGoodsCell()

@property (nonatomic,strong) UILabel *titleLB;

@property (nonatomic,strong) UIView *bgView;

@property (nonatomic,strong) UIView *goodsBgView;
@property (nonatomic,strong) UIImageView *goodsImgV;//商品图片
@property (nonatomic,strong) UILabel *goodsInfoLB;//商品介绍lb
@property (nonatomic,strong) UILabel *goodsSkuLB;//商品型号lb
@property (nonatomic,strong) UILabel *goodsPriceLB;//商品价格lb
@property (nonatomic,strong) UILabel *goodsNumberLB;//商品数量lb
@property (nonatomic,strong) UIButton *refundBtn;//退款btn

@property (nonatomic,strong) UILabel *priceLB;//商品价格数量总计
@property (nonatomic,strong) UILabel *paymentLB;//商品实付款总计


@property (nonatomic,strong) OrderRefundView *refundView;//退款view

@end

@implementation OrderParticularsGoodsCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = MainBackColor;
        self.contentView.backgroundColor = MainBackColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

#pragma mark - setter
- (void)setModel:(OrderParticularsModel *)model{
    _model = model;
    
    self.goodsBgView.height = (_model.refundbtn == YES ? 140:110);
    self.refundBtn.hidden = !_model.refundbtn;
    
    [self.goodsImgV sd_setImageWithURL:[NSURL URLWithString:_model.picture]];
    self.goodsInfoLB.text = _model.name;
    self.goodsSkuLB.text = _model.norms;
    self.goodsSkuLB.width = [Configuration getLabelWidthWithText:self.goodsSkuLB.text withFont:self.goodsSkuLB.font];
    
    self.goodsPriceLB.text = [Configuration getTotalPriceWithPrice:_model.price withTbPrice:_model.tbprice];
    self.goodsNumberLB.text = [NSString stringWithFormat:@"X%ld",(long)_model.number];
    
    self.priceLB.text = [NSString stringWithFormat:@"共%ld件商品  共计 %@",_model.number,[Configuration getTotalPriceWithPrice:_model.payprice withTbPrice:_model.totaltbprice]];
    self.paymentLB.text = [NSString stringWithFormat:@"实付：%@",[Configuration getTotalPriceWithPrice:_model.payprice withTbPrice:_model.totaltbprice]];
    self.priceLB.top = self.goodsBgView.bottom + 20;
    self.paymentLB.top = self.priceLB.bottom + 11;
    
    self.bgView.height = self.goodsBgView.height + 95;
    if ([_model.refundid isEmpty]==NO && _model.refundid.length>0) {
        self.refundView.hidden = NO;
        self.refundView.top = self.paymentLB.bottom + 24;
        self.bgView.height = self.goodsBgView.height + 95 + 210;
        self.refundView.refundNoLB.text = _model.refundid;
        self.refundView.refundTimeLB.text = _model.refunddate;
        self.refundView.refundPriceLB.text = _model.refundprice;
        self.refundView.refundReasonLB.text = _model.refundnote;
    }else{
        self.refundView.hidden = YES;
    }
    
    float cellHeight = self.bgView.bottom;
    if (self.updateCellHeightBlock) {
        self.updateCellHeightBlock(cellHeight);
    }
}

#pragma mark - UI
-(void)initUI{
    
    [self.contentView addSubview:self.titleLB];
    [self.contentView addSubview:self.bgView];
    
    [self.bgView addSubview:self.goodsBgView];
    [self.bgView addSubview:self.priceLB];
    [self.bgView addSubview:self.paymentLB];
    [self.bgView addSubview:self.refundView];
    
    [self.goodsBgView addSubview:self.goodsImgV];
    [self.goodsBgView addSubview:self.goodsInfoLB];
    [self.goodsBgView addSubview:self.goodsSkuLB];
    [self.goodsBgView addSubview:self.goodsPriceLB];
    [self.goodsBgView addSubview:self.goodsNumberLB];
    [self.goodsBgView addSubview:self.refundBtn];
}

#pragma mark - lazy
- (UILabel *)titleLB{
    if (!_titleLB) {
        _titleLB = [[UILabel alloc] initWithFrame:CGRectMake(17, 23, 120, 20)];
        _titleLB.textColor = MainBlackTextColor;
        _titleLB.font = FontSet(14);
        _titleLB.textAlignment = NSTextAlignmentLeft;
        _titleLB.text = @"商品";
    }
    return _titleLB;
}

- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, self.titleLB.bottom + 8, ScreenWidth, 210)];
        _bgView.clipsToBounds = YES;
        _bgView.layer.cornerRadius = 12;
        _bgView.backgroundColor = UIColor.whiteColor;
    }
    return _bgView;
}
- (UIView *)goodsBgView{
    if (!_goodsBgView) {
        _goodsBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 110)];
        _goodsBgView.backgroundColor = Color_Clear;
    }
    return _goodsBgView;
}
//商品图片
-(UIImageView *)goodsImgV{
    if (!_goodsImgV) {
        _goodsImgV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 80, 80)];
        _goodsImgV.backgroundColor = MainBackColor;
        _goodsImgV.clipsToBounds = YES;
        _goodsImgV.layer.cornerRadius = 4;
    }
    return _goodsImgV;
}
//商品信息简介lb
-(UILabel *)goodsInfoLB{
    if (!_goodsInfoLB) {
        _goodsInfoLB = [[UILabel alloc] initWithFrame:CGRectMake(self.goodsImgV.right+10, self.goodsImgV.top, ScreenWidth - 140, 20)];
        _goodsInfoLB.numberOfLines = 1;
        _goodsInfoLB.textAlignment = NSTextAlignmentLeft;
        _goodsInfoLB.textColor = MainBlackTextColor;
        _goodsInfoLB.font = FontSet(14);
    }
    return _goodsInfoLB;
}
//商品信息简介lb
-(UILabel *)goodsSkuLB{
    if (!_goodsSkuLB) {
        _goodsSkuLB = [[UILabel alloc] initWithFrame:CGRectMake(self.goodsImgV.right+10, self.goodsInfoLB.bottom+8, 50, 17)];
        _goodsSkuLB.textAlignment = NSTextAlignmentLeft;
        _goodsSkuLB.backgroundColor = MainBackColor;
        _goodsSkuLB.textColor = MainGrayTextColor;
        _goodsSkuLB.font = FontSet(12);
        _goodsSkuLB.clipsToBounds = YES;
        _goodsSkuLB.layer.cornerRadius = 2;
    }
    return _goodsSkuLB;
}
//商品价格lb
-(UILabel *)goodsPriceLB{
    if (!_goodsPriceLB) {
        _goodsPriceLB = [[UILabel alloc] initWithFrame:CGRectMake(self.goodsImgV.right+10, self.goodsImgV.bottom - 18, 80, 18)];
        _goodsPriceLB.textAlignment = NSTextAlignmentLeft;
        _goodsPriceLB.textColor = RGB(255, 34, 21);
        _goodsPriceLB.font = FontSetWithWeight(15, 0.2f);
    }
    return _goodsPriceLB;
}
//商品数量简介lb
-(UILabel *)goodsNumberLB{
    if (!_goodsNumberLB) {
        _goodsNumberLB = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth-75, self.goodsImgV.bottom-20, 35, 20)];
        _goodsNumberLB.textAlignment = NSTextAlignmentRight;
        _goodsNumberLB.textColor = MainGrayTextColor;
        _goodsNumberLB.font = FontSet(14);
    }
    return _goodsNumberLB;
}
- (UIButton *)refundBtn{
    if (!_refundBtn) {
        _refundBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _refundBtn.frame = CGRectMake(ScreenWidth-87, 108, 72, 28);
        _refundBtn.clipsToBounds = YES;
        _refundBtn.layer.cornerRadius = 14;
        [_refundBtn setTitleColor:MainPureColor(119) forState:normal];
        _refundBtn.layer.borderWidth = 1;
        _refundBtn.layer.borderColor = MainPureColor(220).CGColor;
        [_refundBtn.titleLabel setFont:FontSet(12)];
        [_refundBtn setTitle:@"申请退款" forState:normal];
        [_refundBtn addTarget:self action:@selector(refundClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _refundBtn;
}

- (UILabel *)priceLB{
    if (!_priceLB) {
        _priceLB = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth - 260, self.goodsBgView.bottom + 20, 244, 18)];
        _priceLB.textColor = MainPureColor(85);
        _priceLB.font = FontSet(13);
        _priceLB.textAlignment = NSTextAlignmentRight;
    }
    return _priceLB;
}
- (UILabel *)paymentLB{
    if (!_paymentLB) {
        _paymentLB = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth - 260, self.priceLB.bottom + 11, 244, 18)];
        _paymentLB.textColor = RGB(255, 54, 43);
        _paymentLB.font = FontSet(13);
        _paymentLB.textAlignment = NSTextAlignmentRight;
    }
    return _paymentLB;
}

- (OrderRefundView *)refundView{
    if (!_refundView) {
        _refundView = [[OrderRefundView alloc] initWithFrame:CGRectMake(0, self.paymentLB.bottom + 24, ScreenWidth, 210)];
        _refundView.backgroundColor = Color_Clear;
        _refundView.hidden = YES;
    }
    return _refundView;
}

#pragma mark - SEL
-(void)refundClick{
    
}



@end
